import { Button, Card } from 'antd';
import React, { Component } from 'react';
import { connect } from 'umi';

class AlarmAudio extends Component {
  constructor(props) {
    super(props);
    this.musicRef = React.createRef();
  }
  componentDidMount() {
    // 当页面组件完全的加载完毕触发此生命周期，只会触发一次
    const { dispatch } = this.props;
    dispatch &&
      dispatch({
        type: 'global/SaveAudioCurrent',
        payload: this.musicRef,
      });
  }

  play() {
    this.musicRef.current.play();
  }
  stop() {
    this.musicRef.current.pause();
  }
  render() {
    return <audio ref={this.musicRef} type="audio/flac" src="./assets/mp3/jingbao.mp3" loop />;
  }
}

export default connect(
  ({}) => ({}),
  (dispatch) => {
    return { dispatch };
  },
  null,
  { forwardRef: true },
)(AlarmAudio);
